<template>
  <div>
    <div v-html="content"></div>

    <div>
      <button @click="$router.push('/shopcar')">跳转购物车</button>
      <button @click="add">加入购物车</button>
    </div>
  </div>
</template>

<script>
import { ref, reactive, toRefs } from "vue";
import { useStore } from "vuex";
import { useRouter, useRoute } from "vue-router";
import { getDetail } from "../utils/yx";
export default {
  setup(props, ctx) {
    const store = useStore();
    const router = useRouter();
    const route = useRoute();
    let id = route.params.id;
    const data = reactive({
      content: [],
      info: {},
    });
    getDetail(id).then((res) => {
      console.log(res);
      data.content = res.data.content;
      data.info = res.data.basicInfo;
    });

    const add = () => {
      store.commit("add", data.info);
    };
    //加入购物车
    return { ...toRefs(data), id, add };
  },
};
</script>

<style lang="scss"></style>
